
#include "CGameApplication.h"

SDL_Event g_Event;

int main(int argc, char *argv[])
{
	CGameApplication *GameApplication = CGameApplication::getInstance();
	GameApplication->initializeApplication();

	FontPtr f = GameApplication->getGameApp()->getFonts()[0];

	std::string coord;
	std::stringstream outCoord;
	
	bool quit = false;

	GameApplication->getCMapManager()->fillMapWithFile(GameApplication->getGameApp()->getCurrentMap(), "mapLevel.txt");
	
	while(quit == false)
	{
		GameApplication->getGameApp()->getTimer()->start();

		while( SDL_PollEvent( &g_Event ) && quit == false )
        {
			if ( g_Event.type == SDL_MOUSEMOTION )
			{
				outCoord.str(std::string());
				outCoord << g_Event.motion.x;
				coord = outCoord.str();

				TextPtr t = GameApplication->getGameApp()->getTexts().at(0);
				t->setText(coord);
				GameApplication->getCTextManager()->drawFonts( t );

				outCoord.str(std::string());
				outCoord << g_Event.motion.y;
				coord = outCoord.str();

				t = GameApplication->getGameApp()->getTexts().at(1);
				t->setText(coord);
				GameApplication->getCTextManager()->drawFonts( t );
			}

			if ( g_Event.type == SDL_QUIT )
			{
				fprintf(stdout,"Quit event has occurred.\n");
				quit = true;
			}
        }

		GameApplication->getCKeyboardHandler()->inputLogic();
		GameApplication->renderApplication();

		SDL_GL_SwapBuffers();
			
		GameApplication->getGameApp()->getTimer()->delay();
	}

	TTF_Quit();
	SDL_Quit();
	return 0;

}
